﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SaleManagement.Controllers;
using SaleManagement.Models;
namespace SaleManagement.modules
{
    public partial class usMatHang : BaseUC
    {
        public string idgood;
        public int row;
        public bool add = false;
        public usMatHang()
            :base()
        {
            InitializeComponent();
        }

        public override void onLoad()
        {
            GoodController obj = new GoodController();
            List<Good_Model> md = obj.getdata(4);
            this.DataGridView.DataSource = md;

        }
        public override void InitGridData()
        {
            this.DataGridView.AutoGenerateColumns = false;
            this.DataGridView.ColumnHeadersVisible = true;
            DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Beige;
            columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
            DataGridView.ColumnHeadersDefaultCellStyle = columnHeaderStyle;

            //id
            //code
            //created_at
            //description
            //expirate
            
            //import_price
            //name
            //retail_price
            //unit_id
            //updated_at
            //ware
            //wholesale_prices
            DataGridViewTextBoxColumn idColumn = new DataGridViewTextBoxColumn();
            idColumn.DataPropertyName = "id";
            idColumn.HeaderText = "Id";

            DataGridViewTextBoxColumn codeColumn = new DataGridViewTextBoxColumn();
            codeColumn.DataPropertyName = "code";
            codeColumn.HeaderText = "Code";
            DataGridViewTextBoxColumn nameColumn = new DataGridViewTextBoxColumn();
            nameColumn.DataPropertyName = "name";
            nameColumn.HeaderText = "Name";
            DataGridViewTextBoxColumn created_atColumn = new DataGridViewTextBoxColumn();
            created_atColumn.DataPropertyName = "created_at";
            created_atColumn.HeaderText = "CreateAt";

            DataGridViewTextBoxColumn expirateColumn = new DataGridViewTextBoxColumn();
            expirateColumn.DataPropertyName = "expirate";
            expirateColumn.HeaderText = "Expirate";

            DataGridViewTextBoxColumn import_priceColumn = new DataGridViewTextBoxColumn();
            import_priceColumn.DataPropertyName = "import_price";
            import_priceColumn.HeaderText = "Import_price";

            DataGridViewTextBoxColumn wholesale_pricesColumn = new DataGridViewTextBoxColumn();
            wholesale_pricesColumn.DataPropertyName = "wholesale_prices";
            wholesale_pricesColumn.HeaderText = "Wholesale Prices";


            DataGridViewTextBoxColumn retail_priceColumn = new DataGridViewTextBoxColumn();
            retail_priceColumn.DataPropertyName = "retail_price";
            retail_priceColumn.HeaderText = "Retail Price";

            
            DataGridViewTextBoxColumn descriptionColumn = new DataGridViewTextBoxColumn();
            descriptionColumn.DataPropertyName = "description";
            descriptionColumn.HeaderText = "Description";

            DataGridView.Columns.Add(idColumn);
            DataGridView.Columns.Add(codeColumn);
            DataGridView.Columns.Add(nameColumn);
            DataGridView.Columns.Add(created_atColumn);

            
            
            DataGridView.Columns.Add(import_priceColumn);
            DataGridView.Columns.Add(wholesale_pricesColumn);
            
            DataGridView.Columns.Add(retail_priceColumn);
            
            
            DataGridView.Columns.Add(descriptionColumn);
            DataGridView.Columns.Add(expirateColumn);
        }
        public override void OnAdd(object sender, EventArgs e)
        {
            add = true;
            frmAdd_Edit_MatHang fm = new frmAdd_Edit_MatHang(this);
            fm.Show();
        }
        public override void OnEdit(object sender, EventArgs e)
        {
            add = false;
            if (idgood != null)
            {
                frmAdd_Edit_MatHang fm = new frmAdd_Edit_MatHang(this);
                fm.Show();
            }
            else
            {
                MessageBox.Show("ban phai chon kho muon sua");
            }
        }
        public override void OnDelete(object sender, EventArgs e)
        {
            if (MessageBox.Show("ban co muon xoa khong", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                GoodController obj = new GoodController();
                if (obj.deleteGood(idgood))
                {
                    MessageBox.Show(obj.mess);

                    onLoad();
                }
            }
        }
        public override void OnGridDataCellClick(object sender, DataGridViewCellEventArgs e)
        {
            idgood = this.DataGridView.SelectedCells[0].Value.ToString();
            row = DataGridView.CurrentCell.RowIndex;
        }

    }
}
